#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//

void solve()
{
	string s1;
	cin>>s1;
	bool have_b=false;
	bool ok=true;

	int num_a=0;
	int num_b=0;
	for(int i=0;i<s1.size();i++)
	{
		if(s1[i]=='A') num_a++;
		if(s1[i]=='B')
		{
			have_b=true,num_b++;
			if(num_a>=num_b) continue;
			else
			{
				ok=false;
				break;
			}
			
		}
	}
	if(s1[s1.size()-1]=='A') ok=false;	

	if(ok&&have_b) cout<<"YES"<<'\n';
	else cout<<"NO"<<'\n';

	
}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}

//AAAABAAABA